const { Service } = require("egg");

class webService extends Service {
    //首页
    async getHomePageData() {
        let bookList = await this.ctx.service.book.getBook({ page:1,total: 3 }) //推荐书
        let blogList = await this.ctx.service.blog.getBlog({ page:1,total: 3 }) //推荐博客
        let videoList = await this.ctx.service.video.getVideo({page:1,total: 3 }) //推荐视频
        let resourceList = await this.ctx.service.resources.getResources({page:1,total:3})
        let recommendBook = await this.ctx.service.book.getBook({ page:1,total: 3 })
        let recommendBlog = await this.ctx.service.blog.getBlog({page:1,total :1})
        return {
            bookList,
            blogList,
            videoList,
            resourceList,
            recommendBook,
            recommendBlog
        }
    }
    async getBookList() {
        let bookList = await this.ctx.service.book.getBook({page:1,total: 100 })
        let recommendBook = await this.ctx.service.book.getBook({ page:1,total: 3 })
        let recommendBlog = await this.ctx.service.blog.getBlog({page:1,total :1})
        return {
            bookList,
            recommendBook,
            recommendBlog
        }
    }
    async getBlogList() {
        let blogList = await this.ctx.service.blog.getBlog({ page:1,total: 100 }) //推荐博客
        let recommendBook = await this.ctx.service.book.getBook({ page:1,total: 3 })
        let recommendBlog = await this.ctx.service.blog.getBlog({page:1,total :1})
        return {
            blogList,
            recommendBook,
            recommendBlog
        }
    }
    async getBlogDetail(id){
        let blog = await this.ctx.service.blog.getBlogDetail(id)
        let recommendBook = await this.ctx.service.book.getBook({ page:1,total: 3 })
        return {
            blog,
            recommendBook
        }
    }
    async getVideoList() {
        let videoList = await this.ctx.service.video.getVideo({ page:1,total: 100 })
        let recommendBook = await this.ctx.service.book.getBook({ page:1,total: 3 })
        let recommendBlog = await this.ctx.service.blog.getBlog({page:1,total :1})
        return {
            videoList,
            recommendBook,
            recommendBlog
        }
    }
    async getVideoDetail(id){
        let video = await this.ctx.service.video. getVideoDetail(id)
        let videoList = await this.ctx.service.video.getVideo({totle:100})
        let recommendBook = await this.ctx.service.book.getBook({ total: 3 })
        return {
            video,
            recommendBook,
            videoList
        }
    }
    async getResourceList() {
        let resourceList = await this.ctx.service.resources.getResources()
        let recommendBook = await this.ctx.service.book.getBook({ total: 3 })
        let recommendBlog = await this.ctx.service.blog.getBlog({total :1})
        return {
            resourceList,
            recommendBook,
            recommendBlog
        }
    }
    async getSectionPage(section_id){
        let sectionDetail = await this.ctx.service.section.getSectionDetail(section_id)
        let bookList = await  this.ctx.service.book.getBook({page:1,total:100})
        let menuList = await  this.ctx.service.section.getSectionsMenu(section_id)
        return{
            sectionDetail,
            bookList,
            menuList
        }
    }
    async getChapterPage(book_id){
        let chapterList = await this.ctx.service.chapter.getChapter(book_id)
        let chapterPage = await this.ctx.service.section.getSectionList(chapterList)
        return {
            chapterList,
            chapterPage
        }

    }

}

module.exports = webService